package com.ww.word.ui.menu;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;

import com.ww.core.widget.dialog.AlertDialog;
import com.ww.core.widget.slidemenu.BaseSlidingFragmentActivity;
import com.ww.word.R;

public class MenuActivity extends BaseSlidingFragmentActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.slidemenu_center_layout);

		super.initSlidingMenu();
		super.initView(savedInstanceState);
	}

	@Override
	protected void onResume() {
		super.onResume();

	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	public void initLeftMenu() {
		setBehindContentView(R.layout.slidemenu_left_menu);
		FragmentTransaction mFragementTransaction = getSupportFragmentManager().beginTransaction();
		Fragment mFrag = new LeftFragment();
		mFragementTransaction.replace(R.id.left_menu_fragment, mFrag);
		mFragementTransaction.commit();
	}
	
	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
			if (mSlidingMenu.isMenuShowing()) {
				showContent();
			} else {
				if (LeftFragment.press ==0) {
					AlertDialog a = new AlertDialog(this);
					a.exitApp();
				} else {
					initLeftMenu();
				}
			}
			return true;
		} else {
			return super.dispatchKeyEvent(event);
		}
	}
}
